package com.link.play.fit.ai.ui.adjust.adjustPage.fragment

import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import com.link.play.fit.ai.R
import com.link.play.fit.ai.base.BaseFragment
import com.link.play.fit.ai.bean.UserGuide
import com.link.play.fit.ai.databinding.AdjustPageFragment3Binding
import com.link.play.fit.ai.ui.adjust.adjustPage.AdjustPageModel

/**
 *Create by SleepDog on 2025-03-24
 */
class AdjustPageFragment3 :
    BaseFragment<AdjustPageFragment3Binding>(AdjustPageFragment3Binding::inflate) {
    private val viewModel: AdjustPageModel by lazy {
        ViewModelProvider(requireActivity())[AdjustPageModel::class.java]
    }
//    private var recentlyGoalData: RecentlyGoalData? = null
    private var userGuide: UserGuide? = null

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initData()
        initListener()
    }

    private fun initData() {
        userGuide = viewModel.getGoalData()
        userGuide?.let {
            initBackGr(it.goal)
        }

    }

    private fun initListener() {
        binding.loseWeightText.setOnClickListener {
            initBackGr(0)
        }
        binding.maintainText.setOnClickListener {
            initBackGr(1)

        }
        binding.gainText.setOnClickListener {
            initBackGr(2)
        }
    }

    private fun initBackGr(position: Int) {
        viewModel.updateGoal(position)

        binding.loseWeightText.setBackgroundResource(R.drawable.bg_a_style_07)
        binding.maintainText.setBackgroundResource(R.drawable.bg_a_style_07)
        binding.gainText.setBackgroundResource(R.drawable.bg_a_style_07)
        activity?.let { binding.loseWeightText.setTextColor(it.getColor(R.color.black_11)) }
        activity?.let { binding.maintainText.setTextColor(it.getColor(R.color.black_11)) }
        activity?.let { binding.gainText.setTextColor(it.getColor(R.color.black_11)) }
        when (position) {
            0 -> {
                activity?.let { binding.loseWeightText.setTextColor(it.getColor(R.color.white)) }
                binding.loseWeightText.setBackgroundResource(R.drawable.bg_a_style_07_green_r10)
            }

            1 -> {
                activity?.let { binding.maintainText.setTextColor(it.getColor(R.color.white)) }
                binding.maintainText.setBackgroundResource(R.drawable.bg_a_style_07_green_r10)
            }

            2 -> {
                activity?.let { binding.gainText.setTextColor(it.getColor(R.color.white)) }
                binding.gainText.setBackgroundResource(R.drawable.bg_a_style_07_green_r10)

            }
        }
        if (position != -1) {
            viewModel.setNextPage(true)
        } else {
            viewModel.setNextPage(false)
        }
        viewModel.setGoalsValue(goal = position)
    }


}